package Objects;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class PathInfo {
	int bestPathHopCount;
	char ig;
	Path bestPath;
	Set<String> intraRouters = new HashSet<String>();
	ArrayList<Path> backupPaths = new ArrayList<Path>();

	public PathInfo() {
		bestPathHopCount = 0;
		ig = 'i';
		bestPath = new Path();
	}

	public int getHopCount() {
		return bestPathHopCount;
	}

	public void setHopCount(int bestPathHopCount) {
		this.bestPathHopCount = bestPathHopCount;
	}

	public char getIG() {
		return ig;
	}

	public void setIG(char destinationIG) {
		this.ig = destinationIG;
	}

	public Set<String> getIntraRouters() {
		return intraRouters;
	}

	public void setIntraRouters(Set<String> intraRouters) {
		this.intraRouters = intraRouters;
	}

	public void addIntraRouter(String intraRouter) {
		intraRouters.add(intraRouter);
	}

	public void removeIntraRouter(String intraRouter) {
		intraRouters.remove(intraRouter);
	}

	public Path getBestPath() {
		return bestPath;
	}

	public void setBestPath(Path path) {
		this.bestPath = path;
	}

	public ArrayList<Path> getBackupPaths() {
		return backupPaths;
	}

	public void setBackupPath(ArrayList<Path> backupPaths) {
		this.backupPaths = backupPaths;
	}

	public void addBackupPath(Path path) {
		backupPaths.add(path);
	}

	public void deleteBackupPath(Path path) {
		backupPaths.remove(path);
	}

	public String getNextHop() {
		return bestPath.getNextHop();
	}

	public String printIntraRouters() {
		String returnString = "";
		Iterator<String> it = intraRouters.iterator();
		while(it.hasNext()){
			returnString += it.next() + ", ";
		}
		if (intraRouters.size() > 0)
			returnString = returnString.substring(0, returnString.length() - 2);
		return returnString;
	}

	public boolean hasIntaRouter(String routerID) {
		//Logger.log(Logger.ALL, "Router ID: "+routerID);
		//Logger.log(Logger.ALL, intraRouters);
		if (intraRouters.contains(routerID)) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public String toString() {
		String table = "";
		table += bestPath.getDestination() + "\t|  " + ig + "  |    " + bestPathHopCount + "\t|  "
				+ bestPath.printPath() + "\n";
		for (int i = 0; i < backupPaths.size(); i++) {
			table += "\t|  " + ig + "  |    " + backupPaths.get(i).getHopCount() + "\t|  "
					+ backupPaths.get(i).printPath() + "\n";
		}
		if (intraRouters.size() > 0)
			table += bestPath.getDestination() + " intra routers: " + printIntraRouters() + "\n";
		return table;
	}
}